/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var mine = 1;
var corporates = 1;
var months = 6;
var idsArray = new Array();


function paginateInvoices(page){
  $('#invoices_list').replaceWith(paginateInvoicesAjax(page));
  //$('#invoices_list').load('/invoice/list?page='+page);
}

function paginateLocations(page){
  $('#invoices_list').replaceWith(paginateLocationsAjax(page));
}

function loadLocationsChart(month,my,corporate){
  mine = my;
  corporates = corporate;
  months = month;
  $('#chart_space').replaceWith(loadLocationsChartAjax(months,mine,corporates,idsArray));
}

function loadIndividualChart(month,my,corporate){
  $('#chart_space').replaceWith(loadIndividualChartAjax(month,my,corporate));
}

function updateLocationsChart() {
   /*idsArray[0] = 10;
   idsArray[1] = 47;*/

   //var txtSelectedValuesObj = document.getElementById('txtSelectedValues');
   var selectedArray = new Array();
   var selObj = document.getElementById('locations_select_menu');
   var i;
   var count = 0;
   for (i=0; i<selObj.options.length; i++) {
     if (selObj.options[i].selected) {
       selectedArray[count] = selObj.options[i].value;
       count++;
     }
   }

   idsArray = selectedArray;
   //txtSelectedValuesObj.value = idsArray;

   $('#chart_space').replaceWith(loadLocationsChartAjax(months,mine,corporates,idsArray));
}

function paginateInvoicesAjax(page){
  $('#progress').show();
  $('#listing').hide();

  return $.ajax({
    type: 'GET',
    url: '/invoice/list?page='+page,
    async: false
  }).complete(function() { $('#progress').hide() ; $('#listing').fadeIn(370); })
  .responseText;
}

function paginateLocationsAjax(page){
  //$('#progress').ajaxStart(function() {
  $('#progress').show();
  $('#listing').hide();
  /*      })
        .ajaxStop(function() {
            $(this).hide();
            $('#listing').fadeIn(370);
        })
    ;*/
  return $.ajax({
    type: 'GET',
    url: '/invoice/locationList?page='+page,
    async: false
  }).complete(function() { $('#progress').hide() ; $('#listing').fadeIn(370); })
  .responseText;
}

function loadLocationsChartAjax(month,my,corporate,childs){
    /*$('#progress_chart').ajaxStart(function() {
        $(this).show();*/
  $('#progress_chart').show();
  $('#chart_space').hide();
    /*    })
        .ajaxStop(function() {
            $(this).hide();
            $('#chart_space').fadeIn(370);
        })
    ;*/

  return $.ajax({
    type: 'GET',
    url: '/invoice/locationsChart?month='+month+'&my='+my+'&corporate='+corporate+'&childs='+childs,
    async: false
  }).complete(function() { $('#progress_chart').hide() ; $('#chart_space').fadeIn(370); })
  .responseText
  ;
}

function loadIndividualChartAjax(month,my,corporate){
  $('#progress_chart').show();
  $('#chart_space').hide();

  return $.ajax({
    type: 'GET',
    url: '/invoice/individualChart?month='+month+'&my='+my+'&corporate='+corporate,
    async: false
  }).complete(function() { $('#progress_chart').hide() ; $('#chart_space').fadeIn(370); })
  .responseText;
}

$(document).ready(function(){
  $('#progress_chart').hide();
  $('#progress').hide();  // hide it initially
        

    $.fx.speeds._default = 400;
    $(function() {
        $( "#dialog" ).dialog({
            autoOpen: false,
            show: "fade",
            hide: "fade"
        });
    });

});

function payNow()
{
    $( "#dialog" ).dialog( "open" );
    return false;
}

